package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.Constant;
import com.jiayang.hhotel.bean.FinanceHandleModel;
import com.jiayang.hhotel.bean.InfoModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.FinanceHandleActivity;
import com.jiayang.hhotel.util.CommonUtil;
import com.jiayang.hhotel.util.LogUtil;
import com.jiayang.hhotel.util.ToastUtil;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/5/25 0025.
 * 财务处理页面逻辑类
 */

public class FinanceHandlePresenter extends XPresent<FinanceHandleActivity> {

    /**
     * 账务处理列表请求
     * @param mpLanguage 语言
     */
    public void asyncListLoad(int mpLanguage){
        Api.getHomeSer().financeHandleList(Constant.PHONE,mpLanguage,1)
                .compose(XApi.<FinanceHandleModel>getApiTransformer())
                .compose(XApi.<FinanceHandleModel>getScheduler())
                .compose(getV().<FinanceHandleModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<FinanceHandleModel>() {

                    @Override
                    protected void onFail(NetError error) {
                        getV().sealPic(error.getType());
                    }

                    @Override
                    public void onNext(FinanceHandleModel Model) {
                        switch (Model.getState()) {
                            case 9://请求成功
                                getV().setAdapter(Model.getPCashierListDtos());
                                break;
                            case -1://失败
                                getV().sealPic(-1);
                                break;
                            case 1002://没有数据
                                getV().sealPic(1002);
                                break;
                        }
                    }
                });
    }

    /**
     * 个人查房/团队查房按钮请求
     * @param mpLanguage 语言
     */
    public void asyncPerOrTeamLoad(int mpLanguage, final int mpCheck, String mpRoom){
        Api.getHomeSer().perOrTeamCheckOut(Constant.PHONE,mpLanguage,mpCheck,mpRoom)
                .compose(XApi.<InfoModel>getApiTransformer())
                .compose(XApi.<InfoModel>getScheduler())
                .compose(getV().<InfoModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<InfoModel>() {

                    @Override
                    protected void onFail(NetError error) {
                        CommonUtil.dismissProgressDialog(getV());
                        ToastUtil.Toast(getV().getString(R.string.net_error),getV());
                    }

                    @Override
                    public void onNext(InfoModel Model) {
                        CommonUtil.dismissProgressDialog(getV());
                        switch (Model.getState()) {
                            case 9://请求成功
                                switch (mpCheck) {
                                    case 0://个人查房
                                        ToastUtil.Toast(getV().getString(R.string.already_submit), getV());
                                        break;
                                    case 1://团队查房
                                        ToastUtil.Toast(getV().getString(R.string.already_submit), getV());
                                        break;
                                }
                                break;
                            case -1://失败
                                break;
                        }
                    }
                });
    }
}
